{
  "name": "Case 50: Utility Bill Sustainability Tracker",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "19J-SnWQV-cIfjXQuZinSTaW-d4cDer5c",
          "mode": "list",
          "cachedResultName": "Case 50 - Utility Bill Folder",
          "cachedResultUrl": "https://drive.google.com/drive/folders/19J-SnWQV-cIfjXQuZinSTaW-d4cDer5c"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "49581b47-0de5-407a-9b0e-6b3c1c4bfc3a",
      "name": "Monitor Utility Bills Folder",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -1072,
        0
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "1a07ec82-8bab-4da6-9aa2-987f59c45459",
      "name": "Download Utility Bill",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -896,
        0
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "3a086181-6b8a-4135-b603-e97ce952dc81",
      "name": "Upload to Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -720,
        0
      ]
    },
    {
      "parameters": {
        "amount": 20
      },
      "id": "c7f7f711-1f03-4832-bb59-c899995a8eb6",
      "name": "Wait for Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -528,
        0
      ],
      "webhookId": "b7239e69-8e6f-47cb-bc9a-c4096837a335"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to Parser\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "4d296bea-d7eb-4ee8-b2b9-60ad888eece3",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -336,
        0
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "9a372cd6-3655-47cd-aa7d-7939a0a9b5ad",
      "name": "Route Based on Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -160,
        0
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to Parser\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "0a0be4f4-8e03-48d2-8437-5972894c5f6e",
      "name": "Extract Parsed Content",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        80,
        -96
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Location",
              "description": "Office location name (e.g., Bangalore HQ, Mumbai Branch)"
            },
            {
              "name": "Bill_Month",
              "description": "Month of the bill (e.g., November, Dec)"
            },
            {
              "name": "Bill_Year",
              "description": "Year of the bill (e.g., 2025)"
            },
            {
              "name": "Bill_Type",
              "description": "Type of utility (Electricity, Water, or Gas)"
            },
            {
              "name": "Consumption_Units",
              "description": "Total consumption in numbers only"
            },
            {
              "name": "Unit_Type",
              "description": "Unit of measurement (kWh for electricity, Liters for water, m3 for gas)"
            },
            {
              "name": "Billing_Days",
              "description": "Number of days in billing period"
            },
            {
              "name": "Previous_Month_Consumption",
              "description": "Previous month consumption if mentioned in bill"
            },
            {
              "name": "Total_Bill_Amount",
              "description": "Total bill amount in rupees"
            }
          ]
        },
        "options": {}
      },
      "id": "353168a7-91a2-4c2f-87c8-cec8cb40791a",
      "name": "AI Data Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        240,
        -96
      ]
    },
    {
      "parameters": {
        "jsCode": "const billData = $input.first().json.output;\n\n// ROBUST NUMBER EXTRACTION\nconst extractNumber = (str) => {\n  if (!str) return 0;\n  const cleaned = str.toString().replace(/[^\\d.-]/g, '');\n  const num = parseFloat(cleaned);\n  return isNaN(num) ? 0 : num;\n};\n\n// EMBEDDED OFFICE DATABASE\nconst officeDatabase = {\n  \"Bangalore HQ\": {\n    baseline_electricity: 15000,\n    baseline_water: 225000,\n    baseline_gas: 350,\n    target_reduction: 20,\n    employee_count: 250\n  },\n  \"Mumbai Branch\": {\n    baseline_electricity: 8500,\n    baseline_water: 135000,\n    baseline_gas: 200,\n    target_reduction: 15,\n    employee_count: 120\n  },\n  \"Delhi Office\": {\n    baseline_electricity: 12000,\n    baseline_water: 180000,\n    baseline_gas: 280,\n    target_reduction: 25,\n    employee_count: 180\n  },\n  \"Hyderabad Center\": {\n    baseline_electricity: 10000,\n    baseline_water: 150000,\n    baseline_gas: 220,\n    target_reduction: 20,\n    employee_count: 150\n  }\n};\n\n// CARBON EMISSION FACTORS (kg CO2 per unit)\nconst emissionFactors = {\n  \"Electricity\": 0.92,\n  \"Water\": 0.000298,\n  \"Gas\": 2.3\n};\n\n// SEASONAL ADJUSTMENT FACTORS\nconst getSeasonalFactor = (month, billType) => {\n  const monthLower = month.toLowerCase();\n  \n  if (billType === 'Electricity') {\n    if (['april', 'may', 'june', 'apr', 'jun'].includes(monthLower)) return 1.25;\n    if (['november', 'december', 'january', 'february', 'nov', 'dec', 'jan', 'feb'].includes(monthLower)) return 0.85;\n  }\n  \n  if (billType === 'Water') {\n    if (['july', 'august', 'september', 'jul', 'aug', 'sep'].includes(monthLower)) return 1.15;\n  }\n  \n  return 1.0;\n};\n\n// Extract bill data\nconst location = billData.Location || 'Unknown';\nconst billMonth = billData.Bill_Month || 'Unknown';\nconst billYear = extractNumber(billData.Bill_Year) || new Date().getFullYear();\nconst billType = billData.Bill_Type || 'Electricity';\nconst consumptionUnits = extractNumber(billData.Consumption_Units);\nconst unitType = billData.Unit_Type || (billType === 'Electricity' ? 'kWh' : billType === 'Water' ? 'L' : 'm3');\nconst billingDays = extractNumber(billData.Billing_Days) || 30;\nconst previousMonthConsumption = extractNumber(billData.Previous_Month_Consumption);\nconst totalBillAmount = extractNumber(billData.Total_Bill_Amount);\n\n// Get office data\nconst officeData = officeDatabase[location] || {\n  baseline_electricity: 10000,\n  baseline_water: 150000,\n  baseline_gas: 250,\n  target_reduction: 20,\n  employee_count: 150\n};\n\nconst employeeCount = officeData.employee_count;\n\n// Determine baseline based on bill type\nlet baseline = 0;\nif (billType.toLowerCase().includes('electric')) {\n  baseline = officeData.baseline_electricity;\n} else if (billType.toLowerCase().includes('water')) {\n  baseline = officeData.baseline_water;\n} else if (billType.toLowerCase().includes('gas')) {\n  baseline = officeData.baseline_gas;\n}\n\nconst targetReduction = officeData.target_reduction;\nconst adjustedBaseline = baseline * (1 - targetReduction / 100);\n\n// Calculate metrics\nconst dailyAverageConsumption = consumptionUnits / billingDays;\n\nconst monthOverMonthChange = previousMonthConsumption > 0 \n  ? ((consumptionUnits - previousMonthConsumption) / previousMonthConsumption * 100) \n  : 0;\n\nconst varianceFromBaseline = baseline > 0 \n  ? ((consumptionUnits - baseline) / baseline * 100) \n  : 0;\n\n// Carbon footprint calculation\nconst emissionFactor = emissionFactors[billType] || 0.5;\nconst carbonFootprint = consumptionUnits * emissionFactor;\n\n// Per capita consumption\nconst perCapitaConsumption = employeeCount > 0 \n  ? (consumptionUnits / employeeCount).toFixed(2) \n  : 'N/A';\n\n// Cost metrics\nconst costPerUnit = consumptionUnits > 0 \n  ? (totalBillAmount / consumptionUnits).toFixed(2) \n  : '0';\n\n// Green Star Rating\nlet greenStarRating = 3;\nif (consumptionUnits <= adjustedBaseline * 0.9) {\n  greenStarRating = 5;\n} else if (consumptionUnits <= adjustedBaseline * 1.05) {\n  greenStarRating = 4;\n} else if (consumptionUnits <= baseline * 1.15) {\n  greenStarRating = 3;\n} else if (consumptionUnits <= baseline * 1.30) {\n  greenStarRating = 2;\n} else {\n  greenStarRating = 1;\n}\n\nconst greenStarDisplay = '⭐'.repeat(greenStarRating);\n\n// Alert Status\nlet alertStatus = 'Green';\nlet alertEmoji = '✅';\nif (varianceFromBaseline > 30) {\n  alertStatus = 'Red Alert';\n  alertEmoji = '🚨';\n} else if (varianceFromBaseline > 15) {\n  alertStatus = 'Yellow Alert';\n  alertEmoji = '⚠️';\n} else if (varianceFromBaseline < 0) {\n  alertStatus = 'Green - Below Baseline';\n  alertEmoji = '🌟';\n}\n\n// Recommendations\nconst recommendations = [];\n\nif (varianceFromBaseline > 30) {\n  recommendations.push('URGENT: Conduct immediate energy audit');\n  recommendations.push('Check HVAC and lighting systems');\n  recommendations.push('Review after-hours usage patterns');\n} else if (varianceFromBaseline > 15) {\n  recommendations.push('Investigate causes of increased consumption');\n  recommendations.push('Review equipment efficiency');\n} else if (varianceFromBaseline < -10) {\n  recommendations.push('Excellent performance - Share best practices with other locations');\n  recommendations.push('Document energy-saving initiatives');\n} else {\n  recommendations.push('Maintain current consumption levels');\n  recommendations.push('Continue monitoring trends');\n}\n\nif (monthOverMonthChange > 20) {\n  recommendations.push(`Month-over-month increase of ${monthOverMonthChange.toFixed(1)}% requires investigation`);\n}\n\n// Seasonal adjustment awareness\nconst seasonalFactor = getSeasonalFactor(billMonth, billType);\nif (seasonalFactor !== 1.0) {\n  recommendations.push(`Note: ${billMonth} has ${seasonalFactor}x seasonal adjustment factor for ${billType}`);\n}\n\n// Potential savings\nconst potentialSavings = varianceFromBaseline > 0 \n  ? ((consumptionUnits - baseline) * parseFloat(costPerUnit)).toFixed(2) \n  : '0';\n\nif (parseFloat(potentialSavings) > 10000) {\n  recommendations.push(`Potential monthly savings: ₹${potentialSavings} if baseline restored`);\n}\n\nreturn {\n  json: {\n    Location: location,\n    Bill_Month: billMonth,\n    Bill_Year: billYear.toString(),\n    Bill_Type: billType,\n    Consumption_Units: consumptionUnits.toFixed(2),\n    Unit_Type: unitType,\n    Billing_Days: billingDays.toString(),\n    Daily_Average_Consumption: dailyAverageConsumption.toFixed(2),\n    Previous_Month_Consumption: previousMonthConsumption > 0 ? previousMonthConsumption.toFixed(2) : 'Not provided',\n    Month_over_Month_Change_Percent: previousMonthConsumption > 0 ? monthOverMonthChange.toFixed(2) + '%' : 'N/A',\n    Baseline_Target: baseline.toFixed(2),\n    Adjusted_Target: adjustedBaseline.toFixed(2),\n    Variance_from_Baseline_Percent: varianceFromBaseline.toFixed(2) + '%',\n    Carbon_Footprint_kg_CO2: carbonFootprint.toFixed(2),\n    Employee_Count: employeeCount.toString(),\n    Per_Capita_Consumption: perCapitaConsumption,\n    Total_Bill_Amount: totalBillAmount.toFixed(2),\n    Cost_Per_Unit: costPerUnit,\n    Green_Star_Rating: `${greenStarRating} ${greenStarDisplay}`,\n    Alert_Status: `${alertEmoji} ${alertStatus}`,\n    Sustainability_Recommendations: recommendations.join('; '),\n    Potential_Monthly_Savings_INR: potentialSavings,\n    Processing_Timestamp: new Date().toISOString()\n  }\n};"
      },
      "id": "28586963-39ba-41f9-97e1-9ef49d799404",
      "name": "Sustainability Intelligence Analyzer",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        528,
        -96
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1RtK26FBG4KVc_pbmSBG6dRaiujxwrhE09Aw0d-1-VwY",
          "mode": "list",
          "cachedResultName": "Case_50_ESG_Sustainability_Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RtK26FBG4KVc_pbmSBG6dRaiujxwrhE09Aw0d-1-VwY/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RtK26FBG4KVc_pbmSBG6dRaiujxwrhE09Aw0d-1-VwY/edit#gid=0"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "Location",
              "displayName": "Location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Bill_Month",
              "displayName": "Bill_Month",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Bill_Year",
              "displayName": "Bill_Year",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Bill_Type",
              "displayName": "Bill_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Consumption_Units",
              "displayName": "Consumption_Units",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Unit_Type",
              "displayName": "Unit_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Billing_Days",
              "displayName": "Billing_Days",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Daily_Average_Consumption",
              "displayName": "Daily_Average_Consumption",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Previous_Month_Consumption",
              "displayName": "Previous_Month_Consumption",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Month_over_Month_Change_Percent",
              "displayName": "Month_over_Month_Change_Percent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Baseline_Target",
              "displayName": "Baseline_Target",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Adjusted_Target",
              "displayName": "Adjusted_Target",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Variance_from_Baseline_Percent",
              "displayName": "Variance_from_Baseline_Percent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Carbon_Footprint_kg_CO2",
              "displayName": "Carbon_Footprint_kg_CO2",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employee_Count",
              "displayName": "Employee_Count",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Per_Capita_Consumption",
              "displayName": "Per_Capita_Consumption",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Total_Bill_Amount",
              "displayName": "Total_Bill_Amount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cost_Per_Unit",
              "displayName": "Cost_Per_Unit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Green_Star_Rating",
              "displayName": "Green_Star_Rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Alert_Status",
              "displayName": "Alert_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Sustainability_Recommendations",
              "displayName": "Sustainability_Recommendations",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Potential_Monthly_Savings_INR",
              "displayName": "Potential_Monthly_Savings_INR",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Processing_Timestamp",
              "displayName": "Processing_Timestamp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "43e3f677-2f83-4a72-9f59-ed9a462d11e0",
      "name": "Log to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        704,
        -96
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\n\nconst location = data.Location || 'Unknown';\nconst billMonth = data.Bill_Month || 'Unknown';\nconst billType = data.Bill_Type || 'Utility';\nconst alertStatus = data.Alert_Status || 'Unknown';\nconst greenRating = data.Green_Star_Rating || '3 ⭐⭐⭐';\n\nconst isAlert = alertStatus.includes('Red') || alertStatus.includes('Yellow');\nconst isAchievement = alertStatus.includes('Green - Below');\n\nconst emailSubject = isAlert \n  ? `${alertStatus} - ${location} ${billType} Bill ${billMonth}` \n  : `Sustainability Report - ${location} ${billMonth} ${billYear}`;\n\nconst emailBody = `Dear Facilities and Sustainability Team,\n\nThe monthly utility bill for ${location} has been processed and analyzed.\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📍 LOCATION DETAILS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nLocation: ${data.Location}\nBilling Period: ${data.Bill_Month} ${data.Bill_Year}\nUtility Type: ${data.Bill_Type}\nBilling Days: ${data.Billing_Days}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n⚡ CONSUMPTION METRICS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nTotal Consumption: ${data.Consumption_Units} ${data.Unit_Type}\nDaily Average: ${data.Daily_Average_Consumption} ${data.Unit_Type}/day\nPrevious Month: ${data.Previous_Month_Consumption}\nMonth-over-Month Change: ${data.Month_over_Month_Change_Percent}\nPer Capita Consumption: ${data.Per_Capita_Consumption} ${data.Unit_Type}/employee\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🎯 BASELINE & TARGET ANALYSIS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nBaseline Target: ${data.Baseline_Target} ${data.Unit_Type}\nAdjusted Target (with reduction goal): ${data.Adjusted_Target} ${data.Unit_Type}\nVariance from Baseline: ${data.Variance_from_Baseline_Percent}\nStatus: ${data.Alert_Status}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🌱 ENVIRONMENTAL IMPACT\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nCarbon Footprint: ${data.Carbon_Footprint_kg_CO2} kg CO₂\nGreen Performance Rating: ${greenRating}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n💰 COST ANALYSIS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nTotal Bill Amount: ₹${data.Total_Bill_Amount}\nCost per Unit: ₹${data.Cost_Per_Unit}\n${parseFloat(data.Potential_Monthly_Savings_INR) > 0 ? `Potential Savings: ₹${data.Potential_Monthly_Savings_INR}/month` : ''}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n✅ SUSTAINABILITY RECOMMENDATIONS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n${data.Sustainability_Recommendations}\n\n${\n  isAlert \n    ? `⚠️ ACTION REQUIRED: This location has exceeded baseline consumption targets and requires immediate attention.` \n    : isAchievement \n    ? `🌟 ACHIEVEMENT: This location is performing below baseline - excellent sustainability performance!` \n    : `📊 PERFORMANCE: This location is within acceptable consumption range.`\n}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nProcessed: ${data.Processing_Timestamp}\n\nThis is an automated analysis from the Utility Bill Sustainability Tracker.\nFor detailed analytics, please check the Google Sheets dashboard.\n\nBest regards,\nAutomated Sustainability System`;\n\nreturn {\n  json: {\n    email_subject: emailSubject,\n    email_body: emailBody,\n    recipient_email: 'facilities.manager@company.com',\n    cc_email: 'sustainability.team@company.com, cfo@company.com',\n    location: location,\n    alert_status: alertStatus,\n    green_rating: greenRating\n  }\n};"
      },
      "id": "2f191c87-6171-425a-8777-dbc97fb72267",
      "name": "Generate Email Summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        912,
        -96
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipient_email }}",
        "subject": "={{ $json.email_subject }}",
        "emailType": "text",
        "message": "={{ $json.email_body }}",
        "options": {}
      },
      "id": "c3bc4c98-48db-410b-856e-a30d32d4c800",
      "name": "Send Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1120,
        -96
      ],
      "webhookId": "eeeff9e9-4efb-4e23-8b07-9e127feefad9",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "85e2d5f0-7e8c-4dad-a153-13480738f6dc",
      "name": "OpenAI GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        240,
        80
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Monitor Utility Bills Folder": {
      "main": [
        [
          {
            "node": "Download Utility Bill",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Utility Bill": {
      "main": [
        [
          {
            "node": "Upload to Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Parser": {
      "main": [
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Route Based on Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Based on Status": {
      "main": [
        [
          {
            "node": "Extract Parsed Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Parsed Content": {
      "main": [
        [
          {
            "node": "AI Data Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Data Extractor": {
      "main": [
        [
          {
            "node": "Sustainability Intelligence Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sustainability Intelligence Analyzer": {
      "main": [
        [
          {
            "node": "Log to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheets": {
      "main": [
        [
          {
            "node": "Generate Email Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Email Summary": {
      "main": [
        [
          {
            "node": "Send Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Data Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d6631882-bf87-4f8e-bfd1-6d6e161c30e6",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "aTcXj96ih2uxtvDL",
  "tags": []
}